//var dataX=['北京','广东','上海','浙江','辽宁','陕西','湖北','河北','山东','福建']
//var data1=[9,7,5,3,3,3,3,3,2,2]
//var data2=[11,12,13,12,3,3,1,11,2,8]
var color1=["#c8fd6f"]
var color2=["#f4b952"]
var color3=["#3acf72"]
var color4=["#3acfcd"]

//var ecBar_data1
var data1=[
	{value:44328,name:'北京'},
	{value:3777,name:'境外'},
	{value:1256,name:'湖南'},
	{value:2040,name:'浙江'},
	{value:1587,name:'广东'},
	{value:1132,name:'江苏'},
	{value:669,name:'河北'},
	{value:627,name:'上海'},
	{value:603,name:'四川'},
	{value:551,name:'湖北'},
	{value:541,name:'安徽'},
	{value:337,name:'陕西'},
	{value:324,name:'福建'},
	{value:271,name:'吉林'},
	{value:255,name:'江西'},
	{value:236,name:'山东'},
	{value:201,name:'河南'},
	{value:200,name:'重庆'},
	{value:137,name:'天津'},
	{value:115,name:'贵州'},
	{value:104,name:'云南'},
	{value:99,name:'辽宁'},
	{value:72,name:'山西'},
	{value:58,name:'甘肃'},
	{value:54,name:'黑龙江'},
	{value:44,name:'海南'},
	{value:20,name:'青海'}
]

var ecBar1_data1 = [
	{name:'北京',value:44328},
	{name:'境外',value:3777},
	{name:'湖南',value:1256},
	{name:'浙江',value:2040},
	{name:'广东',value:1587},
	{name:'江苏',value:1132},
	{name:'河北',value:669},
	{name:'上海',value:627},
	{name:'四川',value:603},
	{name:'湖北',value:551},
	{name:'安徽',value:541},
	{name:'陕西',value:337},
	{name:'福建',value:324},
	{name:'吉林',value:271},
	{name:'江西',value:255},
	{name:'山东',value:236},
	{name:'河南',value:201},
	{name:'重庆',value:200},
	{name:'天津',value:137},
	{name:'贵州',value:115},
	{name:'云南',value:104},
	{name:'辽宁',value:99},
	{name:'山西',value:72},
	{name:'甘肃',value:58},
	{name:'黑龙江',value:54},
	{name:'海南',value:44},
	{name:'青海',value:20}
]

var ecBar1_data2=[
       	{value:25199,name:'北京'},
       	{value:1726,name:'境外'},
       	{value:1241,name:'山东'},
       	{value:938,name:'浙江'},
       	{value:799,name:'广东'},
       	{value:544,name:'河北'},
       	{value:450,name:'江苏'},	
       	{value:341,name:'湖北'},	
       	{value:293,name:'上海'},	
       	{value:280,name:'四川'},	
       	{value:256,name:'湖南'},	
       	{value:190,name:'福建'},	
       	{value:163,name:'陕西'},	
       	{value:150,name:'安徽'},	
       	{value:124,name:'重庆'},	
       	{value:120,name:'江西'},	
       	{value:103,name:'天津'},	
       	{value:82 ,name:'河南'},	
       	{value:56 ,name:'云南'},	
       	{value:56 ,name:'贵州'},	
       	{value:46 ,name:'黑龙江'},	
       	{value:45,name:'辽宁'},	
       	{value:39,name:'吉林'},	
       	{value:30,name:'甘肃'},	
       	{value:24,name:'山西'},	
       	{value:17,name:'海南'},
       	{value:11,name:'青海'},	
   ]
var ecBar1_data3=[
	{value:22267,name:'北京'},	
	{value:1128,name:'境外'},	
	{value:808 ,name:'广东'},	
	{value:783 ,name:'浙江'},	
	{value:488 ,name:'江苏'},	
	{value:384 ,name:'上海'},	
	{value:343 ,name:'四川'},	
	{value:337 ,name:'河北'},	
	{value:296 ,name:'湖北'},	
	{value:233 ,name:'湖南'},	
	{value:172 ,name:'安徽'},	
	{value:144 ,name:'福建'},	
	{value:142 ,name:'重庆'},	
	{value:138 ,name:'陕西'},	
	{value:131 ,name:'天津'},	
	{value:108 ,name:'江西'},	
	{value:104 ,name:'河南'},	
	{value:94,name:'山东'},	
	{value:51,name:'贵州'},	
	{value:47,name:'云南'},	
	{value:42,name:'吉林'},	
	{value:41,name:'辽宁'},	
	{value:31,name:'山西'},	
	{value:30,name:'黑龙江'},	
	{value:30,name:'甘肃'},	
	{value:21,name:'海南'},	
	{value:8, name:'青海'}	
]

var ecBar2_data1 = [
	{value:2748,name:'广东'},	
	{value:2083,name:'四川'},	
	{value:1998,name:'境外'},  
	{value:1783,name:'山东'},	
	{value:1733,name:'福建'},	
	{value:1569,name:'河北'},	
	{value:1207,name:'辽宁'},	
	{value:1057,name:'湖北'},	
	{value:962, name:'重庆'},	
	{value:948, name:'浙江'},	
	{value:444, name:'安徽'},	
	{value:414, name:'湖南'},	
	{value:361, name:'北京'},	
	{value:292, name:'江苏'},	
	{value:262, name:'云南'},	
	{value:195, name:'上海'},	
	{value:188, name:'江西'},	
	{value:175, name:'山西'},	
	{value:112, name:'天津'},	
	{value:79,name:'黑龙江'},	
	{value:66,name:'吉林'},	
	{value:60,name:'河南'},	
	{value:37,name:'贵州'},	
	{value:13,name:'陕西'},	
	{value:5, name:'海南'},	
	{value:3, name:'甘肃'}	
]

var ecBar2_data2 = [
	{value:1032,name:'广东'},	
	{value:950 ,name:'四川'},	
	{value:919 ,name:'山东'},	
	{value:787 ,name:'境外'},	
	{value:603 ,name:'辽宁'},	
	{value:477 ,name:'福建'},	
	{value:420 ,name:'河北'},	
	{value:409 ,name:'湖北'},	
	{value:335 ,name:'重庆'},	
	{value:327 ,name:'浙江'},	
	{value:241 ,name:'安徽'},	
	{value:124 ,name:'湖南'},	
	{value:98  ,name:'北京'},	
	{value:92  ,name:'江苏'},	
	{value:88  ,name:'江西'},	
	{value:84  ,name:'云南'},	
	{value:76  ,name:'天津'},	
	{value:76  ,name:'山西'},	
	{value:58  ,name:'上海'},	
	{value:40  ,name:'河南'},	
	{value:34,name:'黑龙江'},	
	{value:26,name:'贵州'},	
	{value:23,name:'吉林'},	
	{value:5 ,name:'陕西'},	
	{value:2 ,name:'甘肃'},	
	{value:1 ,name:'海南'},	
	{value:1 ,name:'青海'}	
]

var ecBar3_data1 = [
	{name:'山东',value:1824},
	{name:'境外',value:1339},
	{name:'广东',value:1297},
	{name:'北京',value:1136},
	{name:'重庆',value:604},
	{name:'湖北',value:578},
	{name:'福建',value:517},
	{name:'吉林',value:486},
	{name:'天津',value:465},
	{name:'浙江',value:333},
	{name:'江苏',value:286},
	{name:'四川',value:276},
	{name:'陕西',value:271},
	{name:'上海',value:271},
	{name:'河北',value:261},
	{name:'安徽',value:241},
	{name:'山西',value:228},
	{name:'河南',value:179},
	{name:'海南',value:151},
	{name:'辽宁',value:129},
	{name:'甘肃',value:122},
	{name:'黑龙江',value:108},
	{name:'湖南',value:100},
	{name:'贵州',value:63},
	{name:'江西',value:62},
	{name:'云南',value:54},
	{name:'青海',value:2}
]

var ecBar3_data2 = [
	{name:'辽宁',value:4076},
	{name:'陕西',value:3595},
	{name:'北京',value:626},
	{name:'天津',value:390},
	{name:'山东',value:117},
	{name:'河南',value:74},
	{name:'河北',value:70},
	{name:'广东',value:50},
	{name:'浙江',value:48},
	{name:'湖北',value:28},
	{name:'境外',value:16},
	{name:'湖南',value:10},
	{name:'山西',value:10},
	{name:'江苏',value:10},
	{name:'四川',value:6},
	{name:'青海',value:5},
	{name:'甘肃',value:5},
	{name:'江西',value:5},
	{name:'上海',value:5},
	{name:'重庆',value:2},
	{name:'福建',value:2},
	{name:'贵州',value:1}
]

var ecBar3_data3 = [
	{name:'陕西',value:4156},
	{name:'辽宁',value:2595},
	{name:'浙江',value:18},
	{name:'天津',value:15},
	{name:'北京',value:7},
	{name:'境外',value:6},
	{name:'广东',value:3},
	{name:'江苏',value:3},
	{name:'河北',value:2}
] 

var ecBar4_data1 = [
	{name:'广西',value:29121},
	{name:'江苏',value:1219},
	{name:'湖北',value:1007},
	{name:'天津',value:552},
	{name:'山东',value:228},
	{name:'吉林',value:176},
	{name:'重庆',value:153},
	{name:'湖南',value:134},
	{name:'广东',value:79},
	{name:'山西',value:73},
	{name:'境外',value:56},
	{name:'陕西',value:38},
	{name:'北京',value:26},
	{name:'辽宁',value:26},
	{name:'黑龙江',value:13},
	{name:'上海',value:10},
	{name:'江西',value:10},
	{name:'河南',value:3 }
]

var ecBar4_data2 = [
	{name:'海南',value:13563 },
	{name:'内蒙古',value:7106},
	{name:'北京',value:1041},
	{name:'广东',value:547},
	{name:'浙江',value:196},
	{name:'江苏',value:147},
	{name:'福建',value:126},
	{name:'辽宁',value:105},
	{name:'重庆',value:91},
	{name:'天津',value:91},
	{name:'山东',value:42},
	{name:'湖南',value:35},
	{name:'河南',value:34},
	{name:'河北',value:28},
	{name:'陕西',value:21},
	{name:'山西',value:14},
	{name:'四川',value:7},
	{name:'江西',value:7}
]

var ecBar4_data3=[
	{name:'陕西',value:9996},
	{name:'辽宁',value:8446},
	{name:'江苏',value:326},
	{name:'浙江',value:54},
	{name:'天津',value:46},
	{name:'四川',value:35},
	{name:'境外',value:12},
	{name:'江西',value:5},
	{name:'河北',value:5},
	{name:'河南',value:5}
]

var ecBar4_data4 = [
	{name:'广东',value:4270},
	{name:'浙江',value:3931},
	{name:'天津',value:2245},
	{name:'湖北',value:639},
	{name:'福建',value:612},
	{name:'江苏',value:466},
	{name:'江西',value:267},
	{name:'上海',value:125},
	{name:'境外',value:125},
	{name:'陕西',value:76},
	{name:'安徽',value:76},
	{name:'山东',value:6}
]

var ecBar4_data5 =[
	{name:'内蒙古',value:10434},
	{name:'湖北',value:1027},
	{name:'贵州',value:836},
	{name:'天津',value:19},
	{name:'河北',value:17},
	{name:'广东',value:17},
	{name:'北京',value:14},
	{name:'云南',value:7},
	{name:'上海',value:1},
	{name:'湖南',value:1}
]

var ecBar4_data6 = [
	{name:'内蒙',value:6523},
	{name:'广东',value:3369},
	{name:'山西',value:899},
	{name:'天津',value:843},
	{name:'江西',value:838},
	{name:'湖北',value:573},
	{name:'湖南',value:55},
	{name:'浙江',value:34},
	{name:'河北',value:28},
	{name:'黑龙江',value:8},
	{name:'境外',value:5},
	{name:'吉林',value:4},
	{name:'北京',value:2}
]

var data2=[
	{value:156,name:'北京'},
	{value:156,name:'广东'},
	{value:126,name:'上海'},
	{value:126,name:'浙江'},
	{value:16,name:'辽宁'},
	{value:126,name:'陕西'},
	{value:126,name:'湖北'},
	{value:156,name:'河北'},
	{value:156,name:'山东'},
	{value:156,name:'福建'},
]
var data3=[
	{value:56,name:'北京'},
	{value:16,name:'广东'},
	{value:16,name:'上海'},
	{value:126,name:'浙江'},
	{value:161,name:'辽宁'},
	{value:126,name:'陕西'},
	{value:156,name:'湖北'},
	{value:106,name:'河北'},
	{value:356,name:'山东'},
	{value:256,name:'福建'},
]

var data4=[
	{value:256,name:'北京'},
	{value:26,name:'广东'},
	{value:356,name:'上海'},
	{value:226,name:'浙江'},
	{value:161,name:'辽宁'},
	{value:426,name:'陕西'},
	{value:256,name:'湖北'},
	{value:306,name:'河北'},
	{value:356,name:'山东'},
	{value:256,name:'福建'},
]


//x轴和series数据
function xDataSeriesData(data,key){
	var arr=[];
	for(var i=0;i<data.length;i++){
		arr.push(data[i][key])
	}
	return arr
}



var barOption={
    tooltip: {
        trigger: 'axis'
//      axisPointer: {
//          type: 'cross',
//          crossStyle: {
//              color: '#999'
//          }
//      }
    },
    toolbox: {
    	show:false,
        feature: {
            dataView: {show: true, readOnly: false},
            magicType: {show: true, type: ['line', 'bar']},
            restore: {show: true},
            saveAsImage: {show: true}
        }
    },
    /*legend: {
    	show:true,
    	top:'top',
    	textStyle:{
    		color:'#fff'
    	},
      data:[]
    },*/
    grid: {
        left:60,
        top: 35,
        right:10,
        bottom:25
    },
    xAxis: [
        {
          type: 'category',
          data: [],
          axisPointer: {
              type: 'shadow'
          },
          axisLabel:{
          	color:'#c0d4da'
          },
	        axisLine:{
	        	show:true,
	        	lineStyle:{
	        		color:'#c0d4da'
	        	}
	        }
        }
    ],
    yAxis: [
        {
          type: 'value',
          name: '单位/次',
//          min: 0,
//        max: 250,
//        interval: 50,
          axisLabel: {
            color:'#c0d4da'
          },
          axisLine:{
	        	show:true,
	        	lineStyle:{
	        		color:'#c0d4da'
	        	}
        	},
        	splitLine:{
        		lineStyle:{
	        		color:'#272858'
	        	}
        	}
        }
    ],
    series: [{
        name:'访问量',
        type:'bar',
        barWidth:'25%',
        data:[]
     }
    ]
	};



var barChart1 = echarts.init(document.getElementById('ecBar1'))
barChart1.setOption(ecOpt(ecBar1_data1,color1))
var barChart2 = echarts.init(document.getElementById('ecBar2'))
barChart2.setOption(ecOpt(ecBar2_data1,color2))
var barChart3 = echarts.init(document.getElementById('ecBar3'))
barChart3.setOption(ecOpt(ecBar3_data1,color3))
var barChart4 = echarts.init(document.getElementById('ecBar4'))
barChart4.setOption(ecOpt(ecBar4_data1,color4))

/*select(barChart1,$(".caCheck1"),color1,data1,data2)
select(barChart2,$(".caCheck2"),color2,data2,data3)
select(barChart3,$(".caCheck3"),color3,data2,data3)
select(barChart4,$(".caCheck4"),color4,data1,data2,data4)*/

$(".caCheck1").change(function(){
	var n = $(".caCheck1").val();
	var option;
	if(n == 0){
		option=ecOpt(ecBar1_data1,color1);
	}else if(n == 1){
		option=ecOpt(ecBar1_data2,color1);
	}else if(n == 2){
		option=ecOpt(ecBar1_data3,color1);
	}
	barChart1.setOption(option);
});

$(".caCheck2").change(function(){
	var n = $(".caCheck2").val();
	var option;
	if(n == 0){
		option=ecOpt(ecBar2_data1,color2);
	}else if(n == 1){
		option=ecOpt(ecBar2_data2,color2);
	}
	barChart2.setOption(option);
});

$(".caCheck3").change(function(){
	var n = $(".caCheck3").val();
	var option;
	if(n == 0){
		option=ecOpt(ecBar3_data1,color3);
	}else if(n == 1){
		option=ecOpt(ecBar3_data2,color3);
	}else if(n == 2){
		option=ecOpt(ecBar3_data3,color3);
	}
	barChart3.setOption(option);
});

$(".caCheck4").change(function(){
	var n = $(".caCheck4").val();
	var option;
	if(n == 0){
		option=ecOpt(ecBar4_data1,color4);
	}else if(n == 1){
		option=ecOpt(ecBar4_data2,color4);
	}else if(n == 2){
		option=ecOpt(ecBar4_data3,color4);
	}else if(n == 3){
		option=ecOpt(ecBar4_data4,color4);
	}else if(n == 4){
		option=ecOpt(ecBar4_data5,color4);
	}else if(n == 5){
		option=ecOpt(ecBar4_data6,color4);
	}
	barChart4.setOption(option);
});

//下拉框选择
function select(ecObj,selectObj,color,data1,data2){
	var n=0;
	var option=Object;
	selectObj.change(function(){
		n=selectObj.val();
		if(n==0){
			option=ecOpt(ecObj,data1,color)
		}else if(n==1){
			option=ecOpt(ecObj,data2,color)
		}else if(n==2){
			option=ecOpt(ecObj,data3,color)
		}
		ecObj.setOption(option)
	})
}

//参数配置
function ecOpt(ecData,color){
	var data=barOption;
	data.xAxis[0].data=xDataSeriesData(ecData,'name');
	data.series[0].data=xDataSeriesData(ecData,'value');
	data.color=color;
//	data.legend.data=legendSeriesData(ecData,'name');
//	console.log(data)
	return data
}

window.addEventListener('resize',function(){
	barChart1.resize();
	barChart2.resize();
	barChart3.resize();
	barChart4.resize();
})
